<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('设备功率列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <input type="hidden" id="deviceId" name="deviceId" th:value="${deviceId}"/>
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>端口状态：</label>
                                <select name="useStatus" th:with="type=${@dict.getType('cargoStatus')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>启用状态：</label>
                                <select name="status" th:with="type=${@dict.getType('enableStatus')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
<!--                <a class="btn btn-primary" onclick="initCargo()" shiro:hasPermission="biz:cargo:edit">-->
<!--                    <i class="fa fa-gear"></i> 初始化功率-->
<!--                </a>-->
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="biz:cargo:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-success " onclick="sendFee()" shiro:hasPermission="biz:cargo:edit">
                    <i class="fa fa-arrow-circle-down"></i> 下发收费方案
                </a>
                <a  class="btn btn-warning" onclick="closeItem()">
                    <i class="fa fa-reply-all"></i> 返回
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('biz:cargo:edit')}]];
        var removeFlag = [[${@permission.hasPermi('biz:cargo:remove')}]];
        var useStatusDatas = [[${@dict.getType('cargoUseStatus')}]];
        var statusDatas = [[${@dict.getType('enableStatus')}]];
        var goodsCategotyDatas = [[${@udwl.getTableData('biz_goods_category','id','name','enable')}]];
        var prefix = ctx + "biz/cargo";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/puton/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                sortName: "number",
                sortOrder: "asc",
                modalName: "端口电费",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: 'ID',
                    visible: false
                },
                {
                    field: 'tenantId',
                    title: '租户标识',
                    visible: false,
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    field: 'number',
                    title: '端口编号',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    field: 'goodsId',
                    title: '电类型ID',
                    visible: false,
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    field: 'goodsName',
                    title: '电名称',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    field: 'goodsCategory',
                    title: '电分类',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(goodsCategotyDatas, value);
                    }
                },
                {
                    field: 'goodsCostPrice',
                    title: '电进价(KWH/元)',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    field: 'goodsPrice',
                    title: '电售价(KWH/元)',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    field: 'goodsDiscount',
                    title: '折扣',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    field: 'useStatus',
                    title: '端口状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(useStatusDatas, value);
                    }
                },
                {
                    field: 'status',
                    title: '启用状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i> 修改电费</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        function detail(id) {
            var url = prefix + '/detail/' + id + "?time=" + (new Date()).getTime();
            $.modal.openTab("设备功率详情", url);
        }

        /**
         * 下发收费方案
         */
        function sendFee(){
            var deviceId = $("#deviceId").val();
            $.modal.confirm("确定下发收费方案吗？", function() {
                $.operate.get(prefix + "/sendFee?deviceId="+deviceId,function (result){
                    console.log(result);
                })
            })
        }
    </script>
</body>
</html>